<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "../../home/index.js";
import ruleDialog from "../ruleDialog/index.js";
import ruleGoodsListDialog from "../ruleGoodsListDialog/index.js";
export default {
  mixins: [
    Vue.prototype.$vFN.Mixins.Base,
    Vue.prototype.$vFN.Mixins.Edit,
    Vue.prototype.$vFN.Mixins.List,
  ],
  data() {
    return {
      appWindow: window,
      load: true,
      apiUrl: {
        detail: "mall-site-portal/member-rights/getItem", // 详情
        powerRuleList: "mall-site-portal/member-rights/listRule", // 权益规则数据
        delete: "mall-site-portal/member-rights/deleteRule",
        list: "mall-site-portal/member-rights/listRule",
      },

      dataObj: {
        rightName: "", // 权益名称
        rightType: "", // 类型
        remark: "", //说明
        isOpen: "",
        id: "",
      },

      tableData: [], //表格数据

      // 请求携带参数
      mixinList_tableSearchConst: {
        rightId: "",
      },

      // 表格数据删除展示结构
      tableDeleteConfig: {
        width: "400px",
        title: "确定删除?",
        columns: [
          {
            label: "权益规则名称",
            prop: "rightRuleName",
            type: "",
          },
        ],
      },
    };
  },
  methods: {
    async init() {
      this.mixinEdit_editVisible = true;
      // 接受传来的 id
      await this.getDetail(this.rightId);

      this.mixinList_getTable();
      // 显示窗口
    },

    // 获取权益的详情
    async getDetail(id) {
      this.load = true;
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.detail,
          data: {
            id: id,
          },
        },
        window
      );

      if (res._ok) {
        for (const key in this.dataObj) {
          this.dataObj[key] = res.data[key];
        }
      }
      this.load = false;
    },

    // 修改弹框
    toUpdate(params_) {
      Edit.init({
        mixinEdit_parent: this,
        mixinEdit_editType: params_.type,
        rightType: this.dataObj.rightType,
        id: this.dataObj.id,
      });
    },

    // 规则弹窗
    toRuleDialog(params_) {
      ruleDialog.init({
        mixinEdit_parent: this,
        mixinEdit_editType: params_.type,
        rightType: this.dataObj.rightType,
        rightRuleId: params_.ruleId, // 权益规则id
        rightId: this.rightId, // 从power/home页传来的
      });
    },

    //设置商品
    toGoodsList(rightRuleId) {
      ruleGoodsListDialog.init({
        rightRuleId: rightRuleId, //权益规则id
        onSuccess: (res) => {},
      });
    },
  },
  mounted() {
    this.init();
    this.mixinList_tableSearchConst.rightId = this.rightId; //从home页传来
  },
};
</script>
